package com.etc.controller;

import com.etc.entity.Comments;
import com.etc.entity.Movies;
import com.etc.service.CommentsServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    CommentsServiceImpl commentsServiceImpl;

    /**
     * 删除评论
     *
     * @param comment_no 评论编号
     * @return boolean
     */
    @RequestMapping("/delComment")
    @ResponseBody
    public boolean delComment(String comment_no) {
        boolean b = commentsServiceImpl.delComment(comment_no);
        return b;
    }

    /**
     * 添加评论
     *
     * @param comments 评论内容
     * @return boolean
     */
    @RequestMapping("/addComment")
    @ResponseBody
    public boolean addComment(Comments comments) {
        boolean b = commentsServiceImpl.addComment(comments);
        return b;
    }

    /**
     * 查询
     *
     * @param movie_no 电影编号
     * @param pageNum  页数
     * @param pageSize 数量
     * @return pageinfo
     */
    @RequestMapping("/queryAllByMovie")
    @ResponseBody
    public PageInfo<Comments> queryAllByMovie(Integer movie_no, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        PageInfo<Comments> pageInfo = commentsServiceImpl.queryAllByMovie(movie_no, pageNum, pageSize);
        return pageInfo;
    }

    /**
     * 平均评分
     *
     * @param movie_no 电影编号
     * @return String
     */
    @RequestMapping("/avgScore")
    @ResponseBody
    public String avgScore(int movie_no) {
        String v = commentsServiceImpl.avgScore(movie_no);

        if (v == null) {
            v = "0.00";
        }
        return v;
    }

    /**
     * 评论
     *
     * @param user_no  用户编号
     * @param order_no 订单编号
     * @return comment
     */
    @RequestMapping("/queryDtail")
    @ResponseBody
    public Comments queryDtail(Integer user_no, String order_no) {
        Comments comments = commentsServiceImpl.queryDtail(user_no, order_no);
        return comments;
    }

    /**
     * 更新评论
     *
     * @param comments 评论信息
     * @return boolean
     */
    @RequestMapping("/updateComment")
    @ResponseBody
    public boolean updateComment(Comments comments) {
        boolean b = commentsServiceImpl.updateComment(comments);
        return b;
    }

    /**
     * 全部评分
     *
     * @return list
     */
    @RequestMapping("/avgAll")
    @ResponseBody
    public List<Movies> avgAll() {
        List<Movies> list = commentsServiceImpl.avgAll();
        return list;

    }
}
